from waitress import serve
from manage import app
import threading
import multiprocessing
from msgTkinter import msgTkinterClass
from setting import openDbBase

def get_max_threads():
    try:
        num_cores = multiprocessing.cpu_count()
        max_threads = 2 * num_cores + 1
    except Exception as e:
        return 4
    return max_threads

def sratTornado():

    dbproconfig = openDbBase()
    try:
        serve(app, host='0.0.0.0', port=dbproconfig['CHARTPORT'], threads=get_max_threads())
    except Exception as e:
        print('启动失败')
        # msgTkinterClass(isFail=True,msg=repr(e))
        msgTkinterClass().a001(isFail=True,msg=repr(e))

def sratMsg():
    msgTkinterClass().a001()

# 启动线程1进行弹窗提示
thread01 = threading.Thread(target=sratMsg, daemon=True, name="1")
thread01.start()
thread01.join()

# 启动服务
sratTornado()
